<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategy.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script src="/js/plugins/dialog2/js/dialog.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/css/dialog.css">
    <script>
        $(function () {
            var page=$('#currentPage');
            var pages = 2;
            var id;
            $.get('/regions',{state:1},function (data) {
                var temp = "";
                var content="";
                $.each(data,function (index, ele) {
                    temp+='<li class="nav-item"><a data-id="'+ele.id+'" class="nav-link" id="pills-1-tab" data-toggle="pill" href="#pills-'+ele.id+'">'+ele.name+'</a></li>';
                    content += '<div class="tab-pane fade" id="pills-'+ele.id+'"></div>';
                });
                $('#pills-tab').append(temp);
                $('#pills-tabContent').append(content);
                $('.nav-link').click(function () {
                    id = $(this).data('id');
                    $.get('/regions/'+id+'/strategies',function (data) {
                        $('#pills-'+id).html(data);
                    },'html');
                    page.val(2);
                });
                
            });
            function send() {
                $.get('/regions/'+id+'/strategies',{currentPage:page.val()},function (data) {
                    var temp = "";
                    $.each(data.list,function (index, ele) {
                        console.log(ele.id);
                        temp += '<div class="col-6 mb">\n' +
                            '                <a href="/strategyCatalogs.html?strategyId='+ele.id+'">\n' +
                            '                    <img class="float-left " src="'+ele.coverUrl+'">\n' +
                            '                    <div class="classify-text">\n' +
                            '                        <span>'+ele.title+'</span>\n' +
                            '                        <p>0人收藏</p>\n' +
                            '                    </div>\n' +
                            '                </a>\n' +
                            '            </div>'
                    });
                    console.log(temp);
                    page.val(parseInt(page.val()) + 1);
                    pages = data.pages;
                    $('.classify').append(temp);
                },'json');
            }
            $(window).scroll(function () {
                if ($(document).scrollTop()+$(window).height()>=$(document).height()){
                    if (page.val() <= pages){
                        send();
                    }else {
                        $(document).dialog({
                            type : 'notice',
                            infoText: '已经到底啦！',
                            autoClose: 1500,
                            position: 'bottom'  // center: 居中; bottom: 底部
                        });
                    }
                }
            });
            $.get('/travels/commends', {currentPage: 1, pageSize: 1, type: 3}, function (data) {
                $('.commend').renderValues(data, {
                    getHref: function (item, value) {
                        var href = $(item).data('href');
                        $(item).attr('href', href + value);
                    }
                });
                //$('.travel:first').addClass('active');
            });
            $.get('/strategies',{state:1,pageSize:0}, function (data) {
                $('.strategyCommend').renderValues(data, {
                    getHref: function (item, value) {
                        var href = $(item).data('href');
                        $(item).attr('href', href + value);
                    }
                });
            });


            $('.searchBtn').click(function () {
                var title = $('.searchBtn').val()
                if (title) {
                    $.get('/strategies/strategyTitles',{title:title},function (data) {
                        window.location.href="/strategyCatalogs.html?strategyId="+data.id;

                    })
                }

            })
        });
    </script>
</head>

<body>
<input type="hidden" name="currentPage" id="currentPage" value="2">
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="找攻略">
            </div>
        </div>
    </div>
</div>

<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
    <li class="nav-item">
        <a class="nav-link active show" id="pills-top-tab" data-toggle="pill" href="#pills-top">
            <span style="font-weight: bold;">推荐</span>
        </a>
    </li>
</ul>

<div class="tab-content" id="pills-tabContent">
    <div class="tab-pane fade active show" id="pills-top">
        <div class="container commend">
            <div render-loop="list">
                    <a data-href="travelContent.html?id=" render-key="list.travel_id" render-fun="getHref">
                        <img render-src="list.coverUrl">
                        <p render-html="list.title"></p>
                    </a>
            </div>
        </div>
        <hr>
        <div class="container strategyCommend">
            <h6>当季推荐</h6>
            <div class="row hot" render-loop="list">
                <div class="col-4">
                    <a data-href="strategyCatalogs.html?strategyId=" render-key="list.id" render-fun="getHref">
                        <img render-src="list.coverUrl">
                        <p render-html="list.title"></p>
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

</html>